﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMyTaskCount : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MyTaskCountOutParam result = new MyTaskCountOutParam();
            MyTaskCountInParam param = new MyTaskCountInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MyTaskCountInParam;
                if (string.IsNullOrEmpty(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户ID不能为空";

                    isFlag = false;
                }


                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetMyTaskCount(param.user_id);
                    if (ds != null && ds.Tables.Count == 4)
                    {
                        result.data.branch_activity_todos = ds.Tables[1].Rows[0][0].ToString();
                        result.data.party_care_todos = ds.Tables[3].Rows[0][0].ToString();
                        result.data.party_meeting_todos = ds.Tables[0].Rows[0][0].ToString();
                        result.data.vol_activity_todos = ds.Tables[2].Rows[0][0].ToString();
                    }
                    else
                    {
                        result.data.branch_activity_todos = "0";
                        result.data.party_care_todos = "0";
                        result.data.party_meeting_todos = "0";
                        result.data.vol_activity_todos = "0";
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMyTaskCount", SerializeHelper.JsonSerializer<MyTaskCountInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MyTaskCountInParam, MyTaskCountOutParam>();
            else
                SafeProcessRequest<MyTaskCountInParam, MyTaskCountOutParam>();
        }
    }

    #region 请求参数
    public class MyTaskCountInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class MyTaskCountOutParam
    {
        public MyTaskCountOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MyTaskCount();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 各待办事项的待办数量
        /// </summary>
        public MyTaskCount data
        { get; set; }
    } 

    /// <summary>
    /// 各待办事项的待办数量
    /// </summary>
    public class MyTaskCount
    {
        /// <summary>
        ///	三会一课待办数量 
        /// </summary>
        public string party_meeting_todos
        { get; set; }

        /// <summary>
        ///	支部活动待办数量 
        /// </summary>
        public string branch_activity_todos
        { get; set; }

        /// <summary>
        ///	志愿活动待办数量 
        /// </summary>
        public string vol_activity_todos
        { get; set; }

        /// <summary>
        ///	党内关爱待办数量 
        /// </summary>
        public string party_care_todos
        { get; set; } 
    }
    #endregion 
}